package com.hxd.mall.network.module

import com.google.gson.Gson
import com.hxd.mall.constant.HxdConstantsNet
import dagger.Module
import dagger.Provides
import okhttp3.OkHttpClient
import retrofit2.Retrofit
import retrofit2.adapter.rxjava2.RxJava2CallAdapterFactory
import retrofit2.converter.gson.GsonConverterFactory
import javax.inject.Named
import javax.inject.Singleton

/**
 * 支持多个Retrofit实例创建，区分不同host或其他特使网路请求处理
 *
 * Created by qishuai on 2018/7/30.
 */
/**
 * 未使用，使用的是OkHttpManager
 */
@Module
class RetrofitModule {

    @Singleton
    @Provides
    @Named("default")
    fun providerMainRetrofit(@Named("default") okHttpClient: OkHttpClient): Retrofit {
        return Retrofit.Builder()
            .addConverterFactory(GsonConverterFactory.create(Gson()))
            .addCallAdapterFactory(RxJava2CallAdapterFactory.create())
            .client(okHttpClient)
            .baseUrl(HxdConstantsNet.HOST_URL_ONLINE)
            .build()
    }

}